<?php

// 产品管理首页
class QueryAction extends Action
{

public function _initialize()
{
checkLoginSession();
}

public function index()
{

//$this->assign('content', 'Query:default');

$this->display('Query:default');

}

public function q()
{

if (isset($_GET['tablex']))
{
$tname = $_GET['tablex'];
Session::set('Qtbname', $_GET['tablex']);
} else
{
$tname = $_SESSION['Qtbname'];
}
if($tname=='product_all_info')
{$Field = 'id_tb_product';}
else if($tname=='order_all_info'){$Field = 'id_tb_order';}
else
{$Field = 'id_tb_' . $tname;}

$Asc = ' ASC';
if (isset($_GET['swords']))
{
$swords = $_GET['swords'];
Session::set('swords', $_GET['swords']);
} else
{
if(isset($_SESSION['swords'])){$swords = $_SESSION['swords'];}
else{ $swords ='';}
}


if (isset($_GET['qfield']))
{
$qfield = $_GET['qfield'];
Session::set('qfield', $_GET['qfield']);
} else
{
if(isset( $_SESSION['qfield'])){$qfield = $_SESSION['qfield'];}
}


if (isset($_GET['type']))
{
$type = $_GET['type'];
Session::set('type', $_GET['type']);
} else
{
if(isset($_SESSION['type'])){$type = $_SESSION['type'];}
}

//from to
if (isset($_GET['fromx']))
{
$from = $_GET['fromx'];
Session::set('fromx', $_GET['fromx']);
} else
{
if(isset($_SESSION['fromx'])){$from = $_SESSION['fromx'];}
}

if (isset($_GET['tox']))
{
$to = $_GET['tox'];
Session::set('tox', $_GET['tox']);
} else
{
if(isset($_SESSION['tox'])){$to = $_SESSION['tox'];}
}

if ($type == 'like')
{
$searchwords = $qfield . ' like "%' . $swords . '%"';
} else
{
$searchwords = $qfield . '="' . $swords . '"';
}
if (($tname == 'depot_in') or ($tname == 'order_all_info'))
{

$searchwords = $qfield . ' >= "' . $from . '" and date <= "' . $to . '"';
}


$arrayVa = ShowTable($tname, $Field, $Asc, $searchwords);

$List = $arrayVa['a'];
$page = $arrayVa['b'];
//$this->assign('content', 'Query:' . $tname);
if(isset($swords)){$this->assign('swords', $swords);}

$this->assign('List', $List);
//dump($List);
if (isset($_GET['fromx']))
{
$this->assign('from', $_GET['fromx']);
}
if (isset($_GET['tox']))
{
$this->assign('to', $_GET['tox']);
}
//dump($List);
$this->assign('page', $page);
//$this->display('Index:index');
$this->display('Query:' . $tname);
}


}

?>